package com.version1_4.controller;

import com.alibaba.fastjson.JSONObject;
import com.version1_2.controller.UserController1_2;
import com.version1_3.controller.UserController1_3;
import com.version1_4.service.UserService1_4;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * Created by reeveslee on 16/4/27.
 */
@Controller
public class UserController1_4 {
    private static final Logger LOGGER = Logger.getLogger(UserController1_4.class);

    @Autowired
    private UserController1_3 userController13;

    @Autowired
    private UserController1_2 userController12;

    @Autowired
    private UserService1_4 userService14;

    /**
     * 注销登陆,屏蔽百度云推送
     */
    @RequestMapping(value = "/user/logout/{userId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String logout(@PathVariable("userId") int userId) {
        return userService14.logout(userId);
    }

    /**
     * 登陆用户更新某一个一级分类的关注信息 - 目前iOS只用了SubscriController的changeUserFocus接口
     */
    @RequestMapping(value = "/version1_4/user/sortSecondType/{userId}/{firstType}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String updateFirstFocus(@RequestBody JSONObject jsonObject, @PathVariable("firstType") int firstType, @PathVariable("userId") int userId) {
        return userController13.updateFirstFocus(jsonObject, firstType, userId);
    }

    /**
     * 登陆用户在主界面上对三级分类进行排序置顶
     */
    @RequestMapping(value = "/version1_4/user/topThirdType", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String topThirdType(@RequestBody JSONObject jsonObject) {
        return userController13.topThirdType(jsonObject);
    }

    /**
     * 登陆用户在主界面上取消排序置顶
     */
    @RequestMapping(value = "/version1_4/user/removeTopThirdType", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String removeTopThirdType(@RequestBody JSONObject jsonObject) {
        return userController13.removeTopThirdType(jsonObject);
    }


    /**
     * 更新关注列表 - 目前iOS只用了SubscriController的changeUserFocus接口
     */
    @RequestMapping(value = "/version1_4/user/updateFocusList/{userId}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String updateFocusList(@RequestBody JSONObject jsonObject, @PathVariable("userId") int userId) {
        return userController13.updateFocusList(jsonObject, userId);
    }

    /**
     * 用户登陆
     */
    @RequestMapping(value = "/version1_4/user/login", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String login(@RequestBody JSONObject jsonObject) {
        return userController13.login(jsonObject);
    }

    /**
     * 搜索学校
     */
    @RequestMapping(value = "/version1_4/user/searchSchool/{schoolKey}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String searchSchool(@PathVariable("schoolKey") String schoolKey) {
        return userController13.searchSchool(schoolKey);
    }

    /**
     * 用户注册, 使用邀请码
     */
    @RequestMapping(value = "/version1_4/user/register/{telnumber}/{password:.+}/{inviteCode}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String registerwithInviteCode(@PathVariable("telnumber") String telnumber, @PathVariable("password") String password, @PathVariable("inviteCode") String inviteCode)
            throws UnsupportedEncodingException {
        return userController13.registerwithInviteCode(telnumber, password, inviteCode);
    }

    /**
     * 根据第三方openid获取用户信息 - Android版本
     */
    @RequestMapping(value = "/version1_4/user/thirdPart/login/{openid}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String thirdPartLoginAndroid(@PathVariable("openid") String openid, @RequestBody JSONObject jsonObject) {
        return userController13.thirdPartLoginAndroid(openid, jsonObject);
    }

    /**
     * 用户注册
     */
    @RequestMapping(value = "/version1_4/user/register/{telnumber}/{password:.+}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String register(@PathVariable("telnumber") String telnumber, @PathVariable("password") String password)
            throws UnsupportedEncodingException {
        return userController12.register(telnumber, password);
    }

    /**
     * 检查是否有消息
     */
    @RequestMapping(value = "/version1_4/user/message/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String hasMessage(@PathVariable("userId") int userId) {
        return userController12.hasMessage(userId);
    }


    /**
     * 获取用户回复列表信息
     */
    @RequestMapping(value = "/version1_4/user/message/reply/{userId}/{pageNumber}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getReplyMessage(@PathVariable("userId") int userId,
                                  @PathVariable("pageNumber") int pageNumber)
            throws UnsupportedEncodingException {
        return userController12.getReplyMessage(userId, pageNumber);
    }

    /**
     * 获取用户点赞列表信息
     */
    @RequestMapping(value = "/version1_4/user/message/praise/{userId}/{pageNumber}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getPraiseMessage(@PathVariable("userId") int userId,
                                   @PathVariable("pageNumber") int pageNumber)
            throws UnsupportedEncodingException {
        return userController12.getPraiseMessage(userId, pageNumber);
    }

    /**
     * 获取用户系统消息, 正在写，。需要设计方面给出设计。。
     */
    @RequestMapping(value = "/version1_4/user/message/system/{userId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getSystemMessage(@PathVariable("userId") int userId)
            throws UnsupportedEncodingException {
        return userController12.getSystemMessage(userId);
    }

    /**
     * 登录用户得到收藏列表
     */
    @RequestMapping(value = "/version1_4/user/getCollectList/{userId}/{pageNumber}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getCollectList(@PathVariable("userId") int userId, @PathVariable("pageNumber") int pageNumber)
            throws UnsupportedEncodingException {
        return userController12.getCollectList(userId, pageNumber);
    }

    /**
     * 根据二级分类ID获取用户收藏中特定的二级分类的文章
     */
    @RequestMapping(value = "/version1_4/user/getSecondTypeCollectList/{userId}/{secondType}/{pageNumber}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getSecondTypeCollectList(@PathVariable("userId") int userId, @PathVariable("secondType") int secondType, @PathVariable("pageNumber") int pageNumber) throws UnsupportedEncodingException {
        return userController12.getSecondTypeCollectList(userId, secondType, pageNumber);
    }


    /**
     * 验证用户邮箱或手机号已经被注册
     */
    @RequestMapping(value = "/version1_4/user/checkRegister/{registerInfo}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String checkRegister(@PathVariable("registerInfo") String registerInfo) {
        return userController12.checkRegister(registerInfo);
    }

    /**
     * 忘记密码
     */
    @RequestMapping(value = "/version1_4/user/forgetPass/{telnumber}/{newPassword:.+}", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String forgetPass(@PathVariable("telnumber") String telnumber, @PathVariable("newPassword") String newPassword) {
        return userController12.forgetPass(telnumber, newPassword);
    }

    /**
     * 登陆用户更改密码
     */
    @RequestMapping(value = "/version1_4/user/changePasswd", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String changePasswd(HttpServletRequest request, @RequestBody JSONObject jsonObject)
            throws UnsupportedEncodingException {
        return userController12.changePasswd(request, jsonObject);
    }

    /**
     * 更改用户个人信息
     */
    @RequestMapping(value = "/version1_4/user/updateInfo", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String updateInfo(HttpServletRequest request, @RequestBody JSONObject jsonObject)
            throws UnsupportedEncodingException {
        return userController12.updateInfo(request, jsonObject);
    }

    /**
     * 用户反馈
     */
    @RequestMapping(value = "/version1_4/user/feedback", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String feedback(HttpServletRequest request, @RequestBody JSONObject jsonObject)
            throws UnsupportedEncodingException {
        return userController12.feedback(request, jsonObject);
    }

    /**
     * 记录、删除用户单次收藏,增加积分记录
     */
    @RequestMapping(value = "/version1_4/user/doCollect", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String doCollect(HttpServletRequest request, @RequestBody JSONObject jsonObject)
            throws UnsupportedEncodingException {
        return userController12.doCollect(request, jsonObject);
    }


    /**
     * 删除用户收藏
     */
    @RequestMapping(value = "/version1_4/user/delCollect", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String delCollect(HttpServletRequest request, @RequestBody JSONObject jsonObject)
            throws UnsupportedEncodingException {
        return userController12.delCollect(request, jsonObject);
    }
}
